package com.xyq.friend.service.file;

import com.xyq.common.core.enums.ResultCode;
import com.xyq.common.core.exception.ServiceException;
import com.xyq.common.file.domain.OSSResult;
import com.xyq.common.file.service.OSSService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private OSSService ossService ;

    @Override
    public OSSResult upload(MultipartFile file) {
         try{
           return   ossService.uploadFile(file);
         } catch (Exception e) {
              log.error(e.getMessage());
              // 如果上传错误
             throw new ServiceException(ResultCode.FAILED_FILE_UPLOAD) ;
         }

    }
}
